#include "variable.h"

s16             flash_save_cnt     = -1;
u16             cycle_support[]    = {25, 50, 75, 100, 150, 200, 250, 300, 350, 400, 450, 500};
const u8        cycle_support_size = sizeof(cycle_support);
argument_struct argument           = {FLASH_KEY_WORD};
ADC_SAMP        sample             = {0};

void argument_read_func(argument_struct *dest)
{
    argument_struct temp;
    STMFLASH_Read(FLASH_ARGU_ADDR, (u16 *)&temp.key_word, FLASH_SIZE_ARGU / 2);
    if (temp.key_word == FLASH_KEY_WORD) {
        STMFLASH_Read(FLASH_ARGU_ADDR, (u16 *)&dest->key_word, FLASH_SIZE_ARGU / 2);
    }
}

void argument_save_func(argument_struct src)
{
    argument_struct temp;
    STMFLASH_Read(FLASH_ARGU_ADDR, (u16 *)&temp.key_word, FLASH_SIZE_ARGU / 2);
    if (temp.key_word == FLASH_KEY_WORD) {
        u8 *left  = (u8 *)&temp;
        u8 *right = (u8 *)&src;
        for (int i = 0; i < sizeof(argument_struct); i++) {
            if (*(left + i) != *(right + i)) {
                STMFLASH_Write(FLASH_ARGU_ADDR, (u16 *)&src.key_word, FLASH_SIZE_ARGU / 2);
            }
        }
    } else {
        src.key_word = FLASH_KEY_WORD;
        STMFLASH_Write(FLASH_ARGU_ADDR, (u16 *)&src.key_word, FLASH_SIZE_ARGU / 2);
    }
}
